{% extends "base.html" %}

{% block title %}Tasks{% endblock %}

{% block js %}
{% endblock %}

{% block body %}
<div class="row">
  <div class="col-md-12">
    <h2>Run or schedule action</h2>
    <div class="three-columns">
      {% for a in actions %}
        <a href="{{url_for('celery_tasks.action_run', action_name=a)}}">{{a}}</a><br/>
      {% endfor %}
    </div>
    <h2>Running</h2>
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>ID</th><th>Task</th><th>Arguments</th>
        </tr>
      </thead>
      <tbody>
        {% for host,tasks in inspect_active.items() %}
          {% for task in tasks %}
            <tr>
              <td>{{task["id"]}}</td>
              <td>{{task["name"]}}</td>
              <td>{{task["args"]}}</td>
            </tr>  
          {% endfor %}
        {% endfor %}
      </tbody>
    </table>
    <h2>Queued</h2>
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>ID</th><th>Task</th><th>Arguments</th>
        </tr>
      </thead>
      <tbody>
        {% for host,tasks in inspect_scheduled.items() %}
          {% for task in tasks %}
            <tr>
              <td>{{task["id"]}}</td>
              <td>{{task["name"]}}</td>
              <td>{{task["args"]}}</td>
            </tr>  
          {% endfor %}
        {% endfor %}
      </tbody>
    </table>
    <h2>Schedule</h2>
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>ID</th><th>Name</th><th>Task</th><th>Minute</th><th>Hour</th><th>Day of Week</th><th>Day of Month</th><th>Month</th>
        </tr>
      </thead>
      <tbody>
        {% for pt in periodic_tasks %}
          <tr>
            <td><a href="{{url_for('celery_tasks.schedule_item', pt_id=pt.id)}}">{{pt.id}}</a> {% if pt.enabled %}<i class="fa fa-check"></i>{% else %}<i class="fa fa-ban"></i>{% endif %}</td>
            <td>{{pt.nice_name}}</td>
            <td>{{pt.nice_task}}</td>
            <td>{{pt.crontab_minute}}</td>
            <td>{{pt.crontab_hour}}</td>
            <td>{{pt.crontab_day_of_week}}</td>
            <td>{{pt.crontab_day_of_month}}</td>
            <td>{{pt.crontab_month_of_year}}</td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
    <h2>Results</h2>
      <a href="{{url_for('celery_tasks.results_list')}}">All results</a>
      <table class="table table-bordered">
      <thead>
        <tr>
          <th>ID</th><th>Task</th><th>Time</th><th>State</th>
        </tr>
      </thead>
      <tbody>
        {% for r in task_results %}
          <tr>
            <td><a href="{{url_for('celery_tasks.results_item', result_id=r.id)}}">{{r.id}}</a></td>
            <td>{{r.nice_task}}</td>
            <td>{{r.finished_time.strftime("%Y-%m-%d %H:%M:%S")}}</td>
            <td>{{r.state}}</td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</div>
{% endblock %}
